<template>
  <!-- ... 其他模板代码 ... -->
  <a-upload
    :custom-request="handleUpload"
    :show-file-list="false"
    accept="image/*"
  >
    <!-- ... 其他上传相关的模板 ... -->
  </a-upload>
  <!-- ... 其他模板代码 ... -->
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { Message } from '@arco-design/web-vue';
import { OjFileService } from '@/api/gen-api/services/OjFileService';
import type { FileItem } from '@arco-design/web-vue/es/upload/interface';

// ... 其他代码 ...

const handleUpload = async (option: {
  fileItem: FileItem;
  onSuccess: (response: any) => void;
  onError: (error: any) => void;
}) => {
  try {
    const formData = new FormData();
    formData.append('file', option.fileItem.file as File);
    
    const response = await OjFileService.uploadAvatar(formData);
    
    if (response.code === 0) {
      option.onSuccess(response.result);
      Message.success('头像上传成功');
      // 更新用户头像
      userStore.updateAvatar(response.result);
    } else {
      option.onError(response);
      Message.error(response.message || '上传失败');
    }
  } catch (error: any) {
    option.onError(error);
    Message.error(error.message || '上传失败');
  }
};
</script> 